#define _CRT_SECURE_NO_WARNINGS 1


#include <iostream>
#include<vector>
#include<limits.h>
#include<math.h>
using namespace std;

void getdivisor(int n, vector<int>& v) {
    for (int i = 2; i <= sqrt(n); i++) {
        if (n % i == 0) {
            v.push_back(i);
            if (n / i != i)
            {
                v.push_back(n/i);
            }
        }
    }
}

void min_step(int m, int n, vector<int>& dp) {
    for (int i = m; i < n; i++) {
        if (dp[i] == INT_MAX) {
            continue;
        }
        vector<int> divisor;
        getdivisor(i, divisor);
        for (auto c : divisor) {
            if(i + c <= n)
            dp[i + c] = min(dp[i] + 1, dp[i + c]);
        }
    }
}


int main() {
    int m, n;
    cin >> m >> n;
    vector<int> dp(n + 1, INT_MAX);
    dp[m] = 0;
    min_step(m, n, dp);

    int ret = dp[n] == INT_MAX ? -1 : dp[n];

    cout << ret << endl;
    return 0;
}